﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace Bonobo.Irc.Client
{
    public class UIServerConversation : UIConversation
    {
        private IrcServerConversation _serverConversation;
        private ObservableCollection<IrcMessage> _messages = new ObservableCollection<IrcMessage>();

        public UIServerConversation(IrcSession session) : base(session)
        {
            _serverConversation = _session.ServerConversation;
            _serverConversation.Messages.CollectionChanged += new NotifyCollectionChangedEventHandler(Messages_CollectionChanged);
        }

        public ObservableCollection<IrcMessage> Messages
        {
            get { return _messages; }
        }

        private void Messages_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                foreach (var item in e.NewItems)
                {
                    _sync.Send(() => Messages.Add((IrcMessage)item));
                }                
            }
        }
    }
}
